package com.ruoyi.system.oss.minio;

import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
        import java.security.InvalidKeyException;

        import org.xmlpull.v1.XmlPullParserException;

        import io.minio.MinioClient;
        import io.minio.errors.MinioException;

public class MinioTest {
    public static void main(String[] args) throws NoSuchAlgorithmException, IOException, InvalidKeyException, XmlPullParserException {
        try {
            // 使用MinIO服务的URL，端口，Access key和Secret key创建一个MinioClient对象
            MinioClient minioClient = new MinioClient("http://172.22.60.33:9000", "minioadmin", "minioadmin");

            // 检查存储桶是否已经存在
            boolean isExist = minioClient.bucketExists("2020-06-18");
            if(isExist) {
                System.out.println("Bucket already exists.");
            } else {
                // 创建一个名为asiatrip的存储桶，用于存储照片的zip文件。
                System.out.println("Bucket is't exists.");
                return ;
            }

            // 使用putObject上传一个文件到存储桶中。
            InputStream object = minioClient.getObject("2020-06-18", "2020/06/18/470fc3b97f37373ed7378b0cd67a4ae5.png");
            System.out.println("/home/user/Photos/asiaphotos.zip is successfully uploaded as asiaphotos.zip to `asiatrip` bucket.");
        } catch(MinioException e) {
            System.out.println("Error occurred: " + e);
        }
    }
}
